import { APIS } from '../../constants/fm'

import { InigRequest } from '../../utils/axios'
// import { Env } from '../../env'
import { getRecommendFmResponseTranslator } from './translator'

/**
 * 获取首页推荐广播
 * @see nowiki
 * @api http://fm.xinli001.com/broadcast?pk=99406937
 *
 * @param params
 * @param {string} params.pk [ string ] 广播ID
 *
 */
export function getRecommendFm(params: {
  pk: string
}) {
  return new Promise(async (resolve) => {
    const inigRequest: InigRequest = InigRequest.getInstance()
    await inigRequest
      .get(APIS.getRecommendFm.host + APIS.getRecommendFm.url, params)
      .then((res) => {
        if (res.status != 200) {
          resolve({
            code: res.status,
            message: res.statusText || '失败',
          })
        } else if (res.data.code != 0) {
          resolve({
            code: res.data.code,
            message: res.data.message || '获取失败',
          })
        } else {
          resolve({
            code: 200,
            message: '成功',
            data: getRecommendFmResponseTranslator(res.data.data),
          })
        }
      })
      .catch((err) => {
        resolve({
          code: 1001,
          message: err.message,
        })
      })
  })
}
